home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / util1 / kg_df105.zip / DF.8 next >
Text File  |  1993-03-15  |  14KB  |  348 lines

  1. ;========================================================================== DF.8
  2. ;   Program: Disk Free
  3. ;   Version: 1.05
  4. ;   Creator: Kevin O. Grover, INet: grover@cs.unlv.edu
  5. ;    System: A86 V3.22 by Eric Isaacson
  6. ;  Cre Date: 14 Dec 1988
  7. ;  Mod Date: 15 Mar 1993
  8. ;    Syntax: DF [d:] [?] [/s]
  9. ;   History:
  10. ; ==============================================================================
  11. ;    Date       Vers          Description of Modifications/Additions
  12. ; -----------  ----  -----------------------------------------------------------
  13. ; 14 Dec 1988  1.02  Original Version (as far as I can tell)
  14. ; 16 Feb 1991  1.03  Changed name to DF (from DI, because Norton used DI).
  15. ;                    Added comments, changed address in help, used tabs in help.
  16. ;                    Added Public Domain notice in Help message.
  17. ; 01 Oct 1991  1.04  Added /s option to enable statistics of the drive, they
  18. ;                    are not displayed by default
  19. ; 15 Mar 1993  1.05  Cleaned up text included in executable
  20. ; ==============================================================================
  21. ;
  22. ; Desc:  This program displays the amount of avaliable, used, and free disk
  23. ;        space in bytes.  It also indicates the used and free space in terms
  24. ;        of a percentage of the over all total disk space avaliable.
  25. ;        In addition, sector and clustor information can be printed as
  26. ;        an option.
  27. ;
  28. ; Note:  Syntax for function 36h of Int 21H
  29. ;             AH = 36h
  30. ;             DL = dirve code (0=defualt, 1=A, 2=B, etc..)
  31. ;
  32. ;        On Exit:  if specified drive was vaild:
  33. ;               AX   = Sectors per cluster
  34. ;               BX   = number of available clusters
  35. ;               CX   = bytes per sector
  36. ;               DX   = clusters (allocation untis) per drive
  37. ;             if the specified drive was invalid:
  38. ;               AX   = FFFFh
  39. ;
  40. ; ToDo: - Add /s (stats) option.  If specified, display sector and cluster
  41. ;         information.  Otherwise, only display percentage and usage info.
  42. ;
  43. ; Bugs: - The parsing of the command line does not do many error checks
  44. ;         (it is not very robust, but it is small)
  45. ; ==============================================================================
  46.  
  47. ; ---------------------------------------------------------------------- Equates
  48.  
  49. Width   EQU   14             ; Width of the field to print numbers in
  50. Adjust  EQU   10000          ; Used to compute and format the percentages
  51. CR      EQU   13             ; Carrage return
  52. LF      EQU   10             ; Line Feed
  53. TAB     EQU   9              ; Tab Character
  54.  
  55. ; ----------------------------------------------------------------- Macro: Write
  56.  
  57. Write  Macro
  58.        MOV     AH, 9
  59.        LEA     DX, #1
  60.        INT     21h
  61. #EM
  62.  
  63. ; ----------------------------------------------------------------- Macro: Print
  64.  
  65. Print  Macro
  66.        MOV     Ah, 2
  67.        MOV     DL, #1
  68.        INT     21h
  69. #EM
  70.  
  71. ; ----------------------------------------------------------- Start of MAIN Code
  72.  
  73.          Write   Hello            ; Print opening messages
  74.  
  75.          MOV     DI, 80h         ; Check the command line for /? option for help!
  76.          MOV     CH, 0
  77.          MOV     CL, Byte Ptr [DI]
  78.          JCXZ    SkipOptionCheck  ; If zero, use the defualt drive
  79.  
  80. FindNextOption:
  81.          INC     DI               ; Point to the first byte
  82.          MOV     AL, '/'
  83.          REPNE   Scasb
  84.          JNE     SkipOptionCheck
  85.  
  86.          CMP     Byte Ptr [DI], '?'     ; Check for /? (help) option
  87.          JNE     SkipHelp
  88.          Write   Help                   ; Show help
  89.          MOV     AX, 4C00h              ; Terminate with a zero return code
  90.          INT     21h                    ; Do terminate
  91.  
  92. SkipHelp:
  93.          CMP     Byte Ptr [DI], 's'     ; check for /s (stats) option
  94.          JNE     IllegalOption
  95.          MOV     BYTE PTR ShowStatsFlg, 1        ; Turn Show stats on
  96.          JMP     FindNextOption         ; Look for next Option
  97.  
  98. IllegalOption:
  99.          Write   IllOption              ; Illegal Option
  100.          MOV     AX, 4C01h              ; Terminate with a return code of 1
  101.          INT     21h                    ; Do Terminate
  102.  
  103.          ; Start of Actual Program, i.e. No more option processing
  104.  
  105. SkipOptionCheck:
  106.          MOV     Dl, [05Ch]       ; Get the drive number from the FCB
  107.          MOV     AH, 36h          ; Function to get the disk info
  108.          INT     21h              ; Get the info
  109.          CMP     AX, 0FFFFh       ; Test for an error reading the info
  110.          JNE     NoError          ; If error no error, go on
  111.  
  112.          Write   ErrorM           ; OtherWise, Print and error message, and terminate
  113.          MOV     AX, 4C01
  114.          INT     21h              ; Terminate with return code 1
  115.  
  116. NoError:
  117.          MOV     SecClus, AX      ; Save the returned values.
  118.          MOV     Free, BX
  119.          MOV     ByteSec, CX
  120.          MOV     Total, DX
  121.  
  122.          XOR     DX, DX
  123.          MUL     ByteSec
  124.          MUL     Total
  125.          MOV     TotalBy, AX
  126.          MOV     TotalBy+2, DX
  127.          MOV     BX, Width
  128.          CALL    LNum
  129.          Write   TotalB
  130.  
  131.          MOV     AX, Free         ; Calculate the percent of free space
  132.          MOV     BX, Adjust       ; Multiply by 10000 to give result in the
  133.          MUL     BX               ; form XXXX where it = XX.XX %
  134.          DIV     Total            ; Divide by the total
  135.          MOV     Percent, AX      ; Store the result
  136.  
  137.          MOV     AX, SecClus
  138.          XOR     DX, DX
  139.          MUL     ByteSec
  140.          MUL     Free
  141.          MOV     FreeBy, AX
  142.          MOV     FreeBy+2, DX
  143.          MOV     BX, Width
  144.          CALL    LNum
  145.  
  146.          Write   FS               ; Print the message for free space
  147.          MOV     AX, Percent
  148.          CALL    Per              ; Print the percentage free
  149.  
  150.          MOV     AX, TotalBy
  151.          SUB     AX, FreeBy
  152.          MOV     DX, TotalBy+2
  153.          SBB     DX, FreeBy+2
  154.          MOV     BX, Width
  155.          CALL    LNum
  156.  
  157.          Write   US               ; Print the percent of used space
  158.          MOV     AX, Adjust
  159.          SUB     Ax, Percent      ; Use Percent free to find percent used
  160.          CALL    Per              ; Call the percent output routine
  161.  
  162.          CMP     ShowStatsFlg, 0  ; Should we display statistics?
  163.          JE      SkipStats        ; If not, jump to end
  164.  
  165.          Print   10               ; Leave a Blank Line
  166.          MOV     AX, Total
  167.          MOV     DX, 0
  168.          MOV     BX, Width
  169.          CALL    LNum
  170.          Write   TCluster         ; Print the total number of clusters.
  171.  
  172.          MOV     AX, Free
  173.          MOV     DX, 0
  174.          MOV     BX, Width
  175.          CALL    LNum
  176.          Write   Cluster          ; Print the number of free clusters.
  177.  
  178.          MOV     AX, SecClus
  179.          MOV     DX, 0
  180.          MOV     BX, Width
  181.          CALL    LNum
  182.          Write   Sectors      ; Print the number of sectors per cluster.
  183.  
  184.          MOV     AX, ByteSec
  185.          MOV     DX, 0
  186.          MOV     BX, Width
  187.          CALL    LNum
  188.          Write   BSector      ; Print the number of bytes per sector.
  189.  
  190.  
  191. SkipStats:
  192.          MOV     AX, 4C00h
  193.          INT     21h              ; Quit the program. (Return code = 0)
  194.  
  195. ; -------------------------------------------------------------------------- Per
  196. ;  Per takes the number in AX (xxx) and prints it as a percentage (xx.x%)
  197.  
  198. Per      Proc    Near
  199.          PUSH    AX
  200.          MOV     AH, 2
  201.          MOV     DL, '('
  202.          INT     21h
  203.          POP     AX
  204.          MOV     Bl, 100
  205.          DIV     BL               ; Divide by ten to get the decimal part
  206.          PUSH    AX               ; Save the result on the stack
  207.          MOV     DX, 0
  208.          MOV     Ah, 0            ; Clear the remainder
  209.          MOV     BX, 3            ; Field for the left part
  210.          CALL    Lnum             ; Print the quoitent (the percentage)
  211.          MOV     Dl, '.'          ; Print a decimal point
  212.          MOV     Ah, 2
  213.          INT     21h
  214.          POP     Ax               ; Get the result back from the stack
  215.          MOV     Al,Ah            ; Put the remainder into AL
  216.          MOV     Ah, 0            ; Clear AH leaving the decimal in AX
  217.          CMP     Al, 9            ; Check for a one digit number
  218.          JA      TwoDigits        ; If not, jump ahead
  219.          PUSH    AX               ;  If so, save some registers
  220.          PUSH    DX
  221.          Print   '0'              ; If so, print a '0' to make it two digits.
  222.          POP     DX
  223.          POP     AX
  224. TwoDigits:
  225.          MOV     DX, 0
  226.          MOV     BX, 1
  227.          CALL    Lnum             ; Print the decimal part
  228.          MOV     DL, '%'          ; Print a percentage sign
  229.          MOV     AH, 2
  230.          INT     21h
  231.          MOV     DL, ')'
  232.          INT     21h
  233.          MOV     DL, 13
  234.          INT     21h
  235.          MOV     DL, 10
  236.          INT     21h
  237.          RET
  238. Per      EndP
  239.  
  240. ; ------------------------------------------------------------------------- LNum
  241. ;  Prints a long integer (32 Bits) in DX:AX with a field width specified
  242. ;  in BX.  The number is right justified in the field width specified,
  243. ;  with commas separating the characters where appropriate.
  244.  
  245. LNum     Proc   Near         ;
  246.          PUSH   AX           ; Print a double word as an integer with a specified field width
  247.          PUSH   BX           ;
  248.          PUSH   CX           ;    Number in DX:AX
  249.          PUSH   DX           ;    Field Width in BX
  250.          PUSH   SI           ;
  251.          PUSH   DI           ;
  252.          PUSH   BP           ;
  253.                              ;
  254.          XCHG   BP,DX        ; Save DX in BP
  255.          MOV    DI, BX       ; Save the field width in DI
  256.          MOV    BX, 10       ; MOV BX, 10  - The base to divide by
  257.          MOV    CX, 0        ; Clear the count
  258.          MOV    SI, 0        ;
  259. MoreL:                       ;
  260.                              ;
  261.          CMP    BP, 0        ; See if the MSW is zero
  262.          JZ     OneWord      ; JZ OneWord     (YES)
  263.          XCHG   BP,AX        ; The high word is not zero!, save low word in BP
  264.          XOR    DX,DX        ; Make DX zero
  265.          DIV    BX           ; Divide AX by the base (Quotient in AX, remainder in DX)
  266.          XCHG   BP,AX        ; Get Old Low word backin AX, and put this quotient into BP
  267.          DIV    BX           ; Divide by the base again
  268.          OR     DL, '0'      ; Convert DL to ASCII  (See Note)
  269.          PUSH   DX           ; Store it in memory ont the stack
  270.          INC    CX           ; Increment the count
  271.          INC    SI           ;
  272.          CMP    SI, 3        ;
  273.          JNE    MoreL        ;
  274.                              ;
  275.          MOV    DL, ','      ;
  276.          PUSH   DX           ;
  277.          INC    CX           ;
  278.          MOV    SI, 0        ;
  279.          JMP    MoreL        ; (Go and do the next Number)
  280. OneWord:                     ;
  281.          XOR    DX,DX        ; Clear DX (of the last remainder)
  282.          DIV    BX           ; Divide by the base
  283.          OR     DL, '0'      ; Convert the remainder to ASCII
  284.          PUSH   DX           ; Store it in on the stack
  285.          INC    CX           ; Increment the count
  286.          CMP    AX, 0        ;
  287.          JE     AllDone      ;
  288.          INC    SI           ;
  289.          CMP    SI, 3        ;
  290.          JNE    OneWord      ;
  291.          MOV    DL, ','      ;
  292.          PUSH   DX           ;
  293.          INC    CX           ;
  294.          MOV    SI, 0        ;
  295.          JMP    OneWord      ;
  296. AllDone:                     ;
  297.                              ;
  298.          CMP    CX, DI       ;
  299.          JAE    Ok           ;
  300.          NEG    CX           ;
  301.          ADD    CX, DI       ;
  302.          MOV    DL, ' '      ;
  303. Pad:     PUSH   DX           ;
  304.          LOOP   Pad          ;
  305.          MOV    CX, DI       ;
  306. Ok:                          ;
  307.          MOV    AH, 2        ;
  308. PrintIt: POP    DX           ;
  309.          INT    21h          ;
  310.          LOOP   PrintIt      ;
  311.                              ;
  312.                              ;
  313.          POP    BP           ; Retore the registers used
  314.          POP    DI           ;
  315.          POP    SI           ;
  316.          POP    DX           ;
  317.          POP    CX           ;
  318.          POP    BX           ;
  319.          POP    AX           ;
  320.          RET                 ; Return to the caller
  321. LNum     EndP
  322.  
  323. ; ------------------------------------------------------------------------- Data
  324.  
  325. TotalBy       DW ?,?      ; Total Bytes on the disk
  326. FreeBy        DW ?,?      ; Number of Free bytes
  327. Total         DW ?        ; Total Clusters on the disk
  328. Free          DW ?        ; Number of Free Clusters
  329. SecClus       DW ?        ; Number of Sectors per clustor
  330. ByteSec       DW ?        ; Number of Bytes per sector
  331. Percent       DW ?        ; Used to hold percentage free/used.
  332. ShowStatsFlg  DB 0        ; Flag to show statics about drive (def=FALSE)
  333.  
  334. Hello       DB 'DF-Disk Free V1.05, 1988/1993, Kevin Grover [DF /? for help]',CR,LF,LF,'$'
  335. Help       DB 'Kevin O. Grover, grover@isri.unlv.edu,  CServe: 73627,1677', CR, LF, LF
  336.        DB 'DF displays the number of total/free/used bytes on a disk and the',CR,LF
  337.        DB 'precentage of free and used bytes.  In addition, specifics of the',CR,LF
  338.        DB 'drive can be displayed as an option',CR,LF,LF
  339. IllOption  DB 'Usage:  DF [d:] [/?] [/s]',CR,LF,'$'
  340. TotalB     DB ' bytes total disk space',CR,LF,'$'
  341. FS         DB ' bytes free   $'
  342. US         DB ' bytes used   $'
  343. TCluster   DB ' Total clusters',CR,LF,'$'
  344. Cluster    DB ' Available clusters',CR,LF,'$'
  345. Sectors    DB ' Sectors per cluster',CR,LF,'$'
  346. BSector    DB ' Bytes per sector',CR,LF,'$'
  347. ErrorM     DB TAB,'Invalid drive specification!',LF,'$'
  348.